java.io > FilenameFilter :: 자주 쓰이는 메소드및 API 를 정리합니다.[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

자주 쓰이는 메소드및 API 를 정리합니다.
[1]
등록일:2008-03-18 14:37:44 (0%)
작성자:
제목:java.io > FilenameFilter
implements  FilenameFilter

/*
  *  Output:
  The  0  matching  items  in  the  directory,  ,  are:

  */

import  java.io.File;
import  java.io.FilenameFilter;
import  java.util.Date;

public  class  MainClass  {
    public  static  void  main(String[]  args)  {
        File  myDir  =  new  File("C:/");
        //  Define  a  filter  for  java  source  files  beginning  with  F
        FilenameFilter  select  =  new  FileListFilter("F",  "java");

        File[]  contents  =  myDir.listFiles(select);

        if  (contents  !=  null)  {
            System.out.println("\nThe  "  +  contents.length
                    +  "  matching  items  in  the  directory,  "  +  myDir.getName()
                    +  ",  are:");
            for  (File  file  :  contents)  {
                System.out.println(file  +  "  is  a  "
                                +  (file.isDirectory()  ?  "directory"  :  "file")
                                +  "  last  modified  on\n"
                                +  new  Date(file.lastModified()));
            }
        }  else  {
            System.out.println(myDir.getName()  +  "  is  not  a  directory");
        }
        return;
    }
}

class  FileListFilter  implements  FilenameFilter  {
    private  String  name;  

    private  String  extension;  

    public  FileListFilter(String  name,  String  extension)  {
        this.name  =  name;
        this.extension  =  extension;
    }

    public  boolean  accept(File  directory,  String  filename)  {
        boolean  fileOK  =  true;

        if  (name  !=  null)  {
            fileOK  &=  filename.startsWith(name);
        }

        if  (extension  !=  null)  {
            fileOK  &=  filename.endsWith('.'  +  extension);
        }
        return  fileOK;
    }
}
[본문링크] java.io > FilenameFilter
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=2872
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.